import React from 'react';

import { staff_login } from '../utils/api'
import { Button,Form, Input,message } from 'antd';
import { useNavigate } from 'react-router-dom';
function Login(props) {
    var navigate= useNavigate()
    var onFinish = (values) => {
        staff_login(values).then((res)=>{
            if(res.data.code==200){
                message.success('登录成功');
                localStorage.setItem('userinfo',JSON.stringify(res.data.userInfo))
                localStorage.setItem('token',res.data.token)
                navigate('/index')
            }else{
                message.error('登录失败');
            }
        })

    };
    return (
        <div className='login'>
           <div className="login-box">
              <h2>LOGIN</h2>
              <Form name="normal_login" onFinish={onFinish}>
                    <Form.Item
                        name="phone"
                        rules={[
                            {

                                required: true,
                                message: '请输入手机号!',
                            },
                        ]}
                    >
                        <Input placeholder="请输入手机号" />
                    </Form.Item>

                    <Form.Item
                        name="pass"
                        rules={[
                            {

                                required: true,
                                message: '请输入密码!',
                            },
                        ]}
                    >
                        <Input.Password placeholder="请输入密码" />
                    </Form.Item>

                    <Form.Item>
                        <Button  block type="primary" htmlType="submit"  shape="round">
                            登录
                        </Button>
                    </Form.Item>
                </Form>
           </div>
        </div>
    );
}

export default Login;